Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: static-server can continue if already running #14307

Merged
merged 5 commits into from
Aug 24, 2022

Conversation

paulirish
Copy link
Member

fixes #14302

not trying to get fancy. these are pretty unique ports.

Comment on lines 260 to 266
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => {
if (outcomes.every(o => o.status === 'fulfilled')) return;
if (outcomes.every(o => o.reason.message.includes('already'))) {
return console.warn('😧 Server already up. Continuing…');
}
console.error(outcomes.map(o => o.reason));
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, will this work?

Also we should probably throw an error if the servers fail for an unknown reason

Suggested change
await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost'))).then(outcomes => {
if (outcomes.every(o => o.status === 'fulfilled')) return;
if (outcomes.every(o => o.reason.message.includes('already'))) {
return console.warn('😧 Server already up. Continuing…');
}
console.error(outcomes.map(o => o.reason));
});
const outcomes = await Promise.allSettled(servers.map(s => s.listen(s._port, 'localhost')));
if (outcomes.some(o => o.status === 'rejected')) {
if (outcomes.every(o => o.reason.message.includes('already'))) {
console.warn('😧 Server already up. Continuing…');
} else {
console.error(outcomes.map(o => o.reason));
throw new Error('One or more servers did not start correctly');
}
}
return servers

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your await flow is definitely better. and fixes the error throwing. (i was ending up with an unhandled rejection previously)

i do still prefer the style of my two every()s, but whatever. definitely not a big deal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamraine thanks for writing out the suggestion! :) so clean.

Copy link
Collaborator

@connorjclark connorjclark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval w/ Adam's suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yarn smoke should work when yarn static-server is first called manually
4 participants